|
|
|
|
|
|
|
'Send The Message
objMessage.Send |
|
|
|
|
|
|
|
|
As you can see from the example, Active Messaging uses collections to manage Message, Recipient, and Attachment objects. The code sample first sets up a new Message object and then invokes the Send method to send the message. All of the methods and properties of these objects are listed in the OLEMSG32.DLL file and can be viewed in the Object Browser. |
|
|
|
|
|
|
|
|
The only thing that might be somewhat confusing is the concept of resolving the recipient names. In your e-mail system you have an address book. Resolving simply means taking a friendly name from the address book (for example, "Dad at Work") and converting it to the actual address that the e-mail server uses (SMTP:jsmith@somewhere.com). |
|
|
|
|
|
|
|
|
Accessing the Contents of a Message |
|
|
|
|
|
|
|
|
We have just seen how to send an e-mail message with Active Messaging. You can also use the Messages collection to access unread (or read) messages with Visual Basic code. One possible use for this feature would be to send out an e-mail with a specific subject and then have a program automate replies to the e-mail or store the responses in a database. For example, consider the following code: |
|
|
|
|
|
|
|
|
For Each objMessage In objSession.Inbox.Messages
If objMessage.Unread = True Then
If Instr(objMessage.Subject, "Catalog Request") Then
ProcessMessage objMessage.Text
End If
End If
Next objMessage |
|
|
|
|
|
|
|
|
The sample code uses a For Each loop to iterate through each message in the Messages collection. If a message has not been read (indicated by the Unread property) and the subject contains some specific words, a user-defined function ProcessMessage is called. The ProcessMessage function, which accepts the message text as a parameter, can do any number of things with the message, including initiate a reply or add the contents of the message to a database table. |
|
|
|
|
|
|
|
|
Working with e-mail messages is easy, because each message is represented as an independent object with properties and methods. You can use a For Each loop to browse the Messages collection and process them as desired. The following few lines of code print the subjects of all unread messages that were sent after 7/4/1998: |
|
|
|
|
|
|
|
|
For Each objMessage In objSession.Inbox.Messages
If objMessage.Unread = True And objMessage.Submitted = False Then
If objMessage.TimeSent >= "7/4/98" Then
Debug.Print objMessage.Sender, objMessage.Subject
End If
End If
Next objMessage |
|
|
|
|
|